package travelDream.beans;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import traveldream.ejb.DTO.TransportationDTO;
import traveldream.ejb.interfaces.NotFindException;
import traveldream.ejb.interfaces.TransportEditBeanLocal;


@ManagedBean(name="transportEdit")
@ViewScoped
public class TransportationEditManaged {

	private boolean notprima=false;
	private TransportationDTO tDTO;
	@EJB
	private TransportEditBeanLocal transportEdit;
	
	public TransportationEditManaged(){}
	
	public TransportationDTO gettDTO() {
		return tDTO;
	}
	
	public String edit()
	{
		transportEdit.edit(tDTO);
		return "transportationMean.xhtml?faces-redirect=true";
	}
	
	public void searchById() {
		if(notprima==false)
		{
		FacesContext facesContext = FacesContext.getCurrentInstance();
		int passedParameter = Integer.parseInt((facesContext.getExternalContext().getRequestParameterMap().get("id")));
		try{
		tDTO = transportEdit.find(passedParameter);
		}
		catch(NotFindException e)
		{
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error", "Wrong Id!! please try again!!"));
		}
		notprima=true;
		}
	}
	public void settDTO(TransportationDTO tDTO) {
		this.tDTO = tDTO;
	}


	
	
	
}
